document.addEventListener( "plusready",  function()
{
var _STATUS = "status",
    B = window.plus.bridge;

    var status =
    {
        Login : function (username, password,successCallback,errorCallback)
        {
        var success = typeof successCallback !== 'function' ? null : function(args)
           {
               successCallback(args);
           },
           fail = typeof errorCallback !== 'function' ? null : function(code)
           {
               errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
            return B.exec(_STATUS, "Login", [callbackID,username, password]);
        },
        Logout : function (successCallback,errorCallback)
        {
            var success = typeof successCallback !== 'function' ? null : function(args)
                       {
                           successCallback(args);
                       },
                       fail = typeof errorCallback !== 'function' ? null : function(code)
                       {
                           errorCallback(code);
                       };
                       callbackID = B.callbackId(success, fail);
            return B.exec(_STATUS, "Logout",[callbackID]);
        },
         GenerateConfig : function (datadir,networkID,successCallback,errorCallback)
         {
         var success = typeof successCallback !== 'function' ? null : function(args)
                    {
                        successCallback(args);
                    },
                    fail = typeof errorCallback !== 'function' ? null : function(code)
                    {
                        errorCallback(code);
                    };
                    callbackID = B.callbackId(success, fail);
             return B.exec(_STATUS, "GenerateConfig",[callbackID,datadir,networkID]);
         },
       StartNode : function (nodeConfig ,successCallback,errorCallback)
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
                  {
                      successCallback(args);
                  },
                  fail = typeof errorCallback !== 'function' ? null : function(code)
                  {
                      errorCallback(code);
                  };
                  callbackID = B.callbackId(success, fail);

           return B.exec(_STATUS, "StartNode",[callbackID,nodeConfig]);
       },
       StopNode : function (successCallback, errorCallback )
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
           {
               successCallback(args);
           },
           fail = typeof errorCallback !== 'function' ? null : function(code)
           {
               errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
           return B.exec(_STATUS, "StopNode");
       },
       ValidateNodeConfig : function (callbackID,configJSON,successCallback, errorCallback )
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
           {
               successCallback(args);
           },
           fail = typeof errorCallback !== 'function' ? null : function(code)
           {
               errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
           return B.exec(_STATUS, "ValidateNodeConfig",[callbackID,configJSON]);
       },
       ResetChainData : function (successCallback, errorCallback )
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
           {
               successCallback(args);
           },
           fail = typeof errorCallback !== 'function' ? null : function(code)
           {
               errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
           return B.exec(_STATUS, "ResetChainData",[callbackID]);
       },
       CallRPC : function (inputJSON,successCallback, errorCallback )
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
           {
               successCallback(args);
           },
           fail = typeof errorCallback !== 'function' ? null : function(code)
           {
               errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
           return B.exec(_STATUS, "CallRPC",[callbackID,inputJSON]);
       },
       CallPrivateRPC : function (inputJSON,successCallback, errorCallback )
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
           {
               successCallback(args);
           },
           fail = typeof errorCallback !== 'function' ? null : function(code)
           {
               errorCallback(code);
           };
           callbackID = B.callbackId(success, fail);
           return B.exec(_STATUS, "CallPrivateRPC",[callbackID,inputJSON]);
       },
       CreateAccount : function (password ,successCallback,errorCallback)
       {
       var success = typeof successCallback !== 'function' ? null : function(args)
                  {
                      successCallback(args);
                  },
                  fail = typeof errorCallback !== 'function' ? null : function(code)
                  {
                      errorCallback(code);
                  };
                  callbackID = B.callbackId(success, fail);
           return B.exec(_STATUS, "CreateAccount",[callbackID,password]);
       },
       CreateChildAccount : function (parentAddress,password,successCallback, errorCallback )
          {
          var success = typeof successCallback !== 'function' ? null : function(args)
              {
                  successCallback(args);
              },
              fail = typeof errorCallback !== 'function' ? null : function(code)
              {
                  errorCallback(code);
              };
              callbackID = B.callbackId(success, fail);
              return B.exec(_STATUS, "CreateChildAccount",[callbackID,parentAddress,password]);
          },
         RecoverAccount : function (password,mnemonic,successCallback, errorCallback )
         {
         var success = typeof successCallback !== 'function' ? null : function(args)
             {
                 successCallback(args);
             },
             fail = typeof errorCallback !== 'function' ? null : function(code)
             {
                 errorCallback(code);
             };
             callbackID = B.callbackId(success, fail);
             return B.exec(_STATUS, "RecoverAccount",[callbackID,password,mnemonic]);
         },
         VerifyAccountPassword : function (keyStoreDir,address,password,successCallback, errorCallback )
          {
          var success = typeof successCallback !== 'function' ? null : function(args)
              {
                  successCallback(args);
              },
              fail = typeof errorCallback !== 'function' ? null : function(code)
              {
                  errorCallback(code);
              };
              callbackID = B.callbackId(success, fail);
              return B.exec(_STATUS, "VerifyAccountPassword",[callbackID,keyStoreDir,address,password]);
          },
          ApproveSignRequestWithArgs : function (id, password, gas, gasPrice,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "ApproveSignRequestWithArgs",[callbackID,id, password, gas, gasPrice]);
            },
            ApproveSignRequest : function (id, password,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "ApproveSignRequest",[callbackID,id, password]);
            },
            ApproveSignRequests : function (ids, password,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "ApproveSignRequests",[callbackID,ids, password]);
            },
            DiscardSignRequest : function (id,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "DiscardSignRequest",[callbackID,id]);
            },
            DiscardSignRequests : function (ids,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "DiscardSignRequests",[callbackID,ids]);
            },
            InitJail : function (js )
            {
                return B.exec(_STATUS, "InitJail",[js]);
            },
            Parse : function (chatID,js,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "Parse",[callbackID,chatID,js]);
            },
            CreateAndInitCell : function (chatID,js,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "CreateAndInitCell",[callbackID,chatID,js]);
            },
            ExecuteJS : function (chatID,code,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "ExecuteJS",[callbackID,chatID,code]);
            },
            Call : function (chatID,path,params,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "Call",[callbackID,chatID,path,params]);
            },
            StartCPUProfile : function (dataDir,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "StartCPUProfile",[callbackID,dataDir]);
            },
            StopCPUProfiling : function (successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "StopCPUProfiling",[callbackID]);
            },
            WriteHeapProfile : function (dataDir,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "WriteHeapProfile",[callbackID,dataDir]);
            },
            NotifyUsers : function (message, payloadJSON, tokensArray,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "NotifyUsers",[callbackID,message, payloadJSON, tokensArray]);
            },
            AddPeer : function (enode,successCallback, errorCallback )
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
                {
                    successCallback(args);
                },
                fail = typeof errorCallback !== 'function' ? null : function(code)
                {
                    errorCallback(code);
                };
                callbackID = B.callbackId(success, fail);
                return B.exec(_STATUS, "AddPeer",[callbackID,enode]);
            },
            ConnectionChange : function (typ,expensive)
            {
                return B.exec(_STATUS, "ConnectionChange",[typ,expensive]);
            },
            AppStateChange : function (state)
            {
                return B.exec(_STATUS, "AppStateChange",[state]);
            }
    };
    window.plus.status = status;
}, true );

        /**
         *执行成功后调用successCallback(result)，返回结果在result参数中（如果函数有返回值）
         *执行失败errorCallback(error)，错误原因在error
        */


        //Login loads a key file (for a given address), tries to decrypt it using the password, to verify ownership
        // if verified, purges all the previous identities from Whisper, and injects verified key as shh identity
        function Login(address,password ,successCallback,errorCallback){
            plus.status.Login(address, password ,successCallback,errorCallback);
        }
        //Logout is equivalent to clearing whisper identities
        function Logout(successCallback,errorCallback){
            plus.status.Logout(successCallback,errorCallback);
        }
        //GenerateConfig for status node
        function GenerateConfig(datadir,networkID,successCallback,errorCallback){
            plus.status.GenerateConfig(datadir,networkID,successCallback,errorCallback);
        }
        //StartNode - start Status node
        function StartNode(nodeConfig ,successCallback,errorCallback){
            plus.status.StartNode(nodeConfig);
        }

        //StopNode - stop status node
        function StopNode(successCallback,errorCallback){
            plus.status.StopNode(successCallback,errorCallback);
        }
        //ValidateNodeConfig validates config for status node
        function ValidateNodeConfig(configJSON,successCallback,errorCallback){
            plus.status.ValidateNodeConfig(configJSON);
        }
        //ResetChainData remove chain data from data directory
        function ResetChainData(successCallback,errorCallback){
            plus.status.ResetChainData(successCallback,errorCallback);
        }
        //CallRPC calls public APIs via RPC
        function CallRPC(inputJSON,successCallback,errorCallback){
            plus.status.CallRPC(inputJSON,successCallback,errorCallback);
        }
        //CallPrivateRPC calls both public and private APIs via RPC
       function CallPrivateRPC(inputJSON,successCallback,errorCallback){
            plus.status.CallPrivateRPC(inputJSON,successCallback,errorCallback);
       }
        //CreateAccount is equivalent to creating an account from the command line,
        // just modified to handle the function arg passing
       function CreateAccount(password ,successCallback,errorCallback){
            plus.status.CreateAccount(password,successCallback,errorCallback);
       }
       //CreateChildAccount creates sub-account
       function CreateChildAccount(parentAddress,password,successCallback,errorCallback){
            plus.status.CreateChildAccount(parentAddress,password,successCallback,errorCallback);
       }
       //RecoverAccount re-creates master key using given details
       function RecoverAccount(password,mnemonic,successCallback,errorCallback){
            plus.status.RecoverAccount(password,mnemonic,successCallback,errorCallback);
       }
        //VerifyAccountPassword verifies account password
       function VerifyAccountPassword(keyStoreDir,address,password,successCallback,errorCallback){
            plus.status.VerifyAccountPassword(keyStoreDir,address,password,successCallback,errorCallback);
       }
       //ApproveSignRequestWithArgs instructs backend to complete sending of a given transaction.
       // gas and gasPrice will be overrided with the given values before signing the
       // transaction.
       function ApproveSignRequestWithArgs(id, password, gas, gasPrice,successCallback,errorCallback){
            plus.status.ApproveSignRequestWithArgs(id, password, gas, gasPrice,successCallback,errorCallback);
       }
       //ApproveSignRequest instructs backend to complete sending of a given transaction.
       function ApproveSignRequest(id, password,successCallback,errorCallback){
            plus.status.ApproveSignRequest(id, password,successCallback,errorCallback);
       }
       // //ApproveSignRequests instructs backend to complete sending of multiple transactions
       function ApproveSignRequests(ids, password,successCallback,errorCallback){
            plus.status.ApproveSignRequests(ids, password,successCallback,errorCallback);
       }
       //DiscardSignRequest discards a given transaction from transaction queue
       function DiscardSignRequest(id,successCallback,errorCallback){
            plus.status.DiscardSignRequest(id,successCallback,errorCallback);
       }
       //DiscardSignRequests discards given multiple transactions from transaction queue
       function DiscardSignRequests(ids,successCallback,errorCallback){
            plus.status.DiscardSignRequests(ids,successCallback,errorCallback);
       }
       //InitJail setup initial JavaScript
       function InitJail(js){
            plus.status.InitJail(js);
       }
       //Parse creates a new jail cell context and executes provided JavaScript code.
       //DEPRECATED in favour of CreateAndInitCell.
       function Parse(chatID,js,successCallback,errorCallback){
            plus.status.Parse(chatID,js,successCallback,errorCallback);
       }
       //CreateAndInitCell creates a new jail cell context and executes provided JavaScript code.
       function CreateAndInitCell(chatID,js,successCallback,errorCallback){
            plus.status.CreateAndInitCell(chatID,js,successCallback,errorCallback);
       }
       //ExecuteJS allows to run arbitrary JS code within a cell.
       function ExecuteJS(chatID,code,successCallback,errorCallback){
            plus.status.ExecuteJS(chatID,code,successCallback,errorCallback);
       }
       //Call executes given JavaScript function
       function Call(chatID,path,params,successCallback,errorCallback){
            plus.status.Call(chatID,path,params,successCallback,errorCallback);
       }
       //StartCPUProfile runs pprof for cpu
       function StartCPUProfile(dataDir,successCallback,errorCallback){
            plus.status.StartCPUProfile(dataDir,successCallback,errorCallback);
       }
       //StopCPUProfiling stops pprof for cpu
       function StopCPUProfiling(successCallback,errorCallback){
            plus.status.StopCPUProfiling();
       }
       //WriteHeapProfile starts pprof for heap
       function WriteHeapProfile(dataDir,successCallback,errorCallback){
            plus.status.WriteHeapProfile(dataDir,successCallback,errorCallback);
       }
       // NotifyUsers sends push notifications by given tokens.
       function NotifyUsers(message, payloadJSON, tokensArray,successCallback,errorCallback){
            plus.status.NotifyUsers(message, payloadJSON, tokensArray,successCallback,errorCallback);
       }
       // AddPeer adds an enode as a peer.
       function AddPeer(enode,successCallback,errorCallback){
            plus.status.AddPeer(enode,successCallback,errorCallback);
       }
       // ConnectionChange handles network state changes as reported
       // by ReactNative (see https://facebook.github.io/react-native/docs/netinfo.html)
       function ConnectionChange(typ,expensive,successCallback,errorCallback){
            plus.status.ConnectionChange(typ,expensive,successCallback,errorCallback);
       }
       // AppStateChange handles app state changes (background/foreground).
       function AppStateChange(state){
            plus.status.AppStateChange(state);
       }